#include "./status_task.h"
#include "../heat_driver/sensor.h"
#include "../pub_driver/cmd_can.h"
#include "../heat_driver/ctrl.h"
#include "./draw_hot_task.h"
#include "./draw_tank_task.h"
#include "./heat_task.h"

namespace heat_task {

using namespace heat_driver;
using namespace pub_driver;
using namespace conn;

StatusTask statusTask;

static constexpr uint16_t VERSION = 0x04;

void StatusTask::run() {

    for (;;) {
        sensor.read_temp();

        uint8_t sw2 = sensor->is_leak() |
            (sensor->is_waste_full() << 1) |
            (sensor->is_tank_low() << 2) |
            (sensor->is_tank_high() << 3) |
            (sensor->is_hot_low() << 4) |
            (sensor->is_hot_high() << 5) |
            (sensor->is_steam_temp_ok() << 6) |
            (sensor->is_water_temp_ok() << 7);

        cmdCAN->notify(
            addr::IPC,
            proto::heat::STATUS_UPLOAD,
            VERSION,
            sensor.read(),
            sw2,
            sensor->steam_temp(),
            sensor->water_temp(),
            sensor->flow_count(),
            sensor->adc_value(),
            ctrl.flags(),
            drawTankTask.state(),
            drawHotTask.state(),
            heatTask.state()  
        );
		
		osDelay(500);
    }
}

}
